//
//  LoginViewFromView.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/15.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "LoginViewFromView.h"

@implementation LoginViewFromView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self.backgroundImage addSubview:self.userNum];
        [self.backgroundImage addSubview:self.userPassword];
        [self.backgroundImage addSubview:self.forgetPassword];
        [self.backgroundImage addSubview:self.registerNow];
        [self.backgroundImage addSubview:self.login];
        [self.backgroundImage addSubview:self.dividingImage];
        [self.backgroundImage addSubview:self.QQLogin];
        [self.backgroundImage addSubview:self.WeChatLogin];
        [self.backgroundImage addSubview:self.SinaLogin];
        [self addSubview:self.backgroundImage];
        [self showLoginView];
    }
    return self;
}

- (void)showLoginView
{
    _backgroundImage.sd_layout
    .topSpaceToView(self,0)
    .leftSpaceToView(self,0)
    .rightSpaceToView(self,0)
    .bottomSpaceToView(self,0);
    
    _userNum.sd_layout
    .topSpaceToView(self.backgroundImage,kHeightScale(296))
    .leftSpaceToView(self.backgroundImage,kWidthScale(62))
    .rightSpaceToView(self.backgroundImage,kWidthScale(62))
    .heightIs(kHeightScale(44));
    
    _userPassword.sd_layout
    .topSpaceToView(self.userNum,kHeightScale(15))
    .leftEqualToView(self.userNum)
    .rightEqualToView(self.userNum)
    .heightIs(kHeightScale(44));
    
    _forgetPassword.sd_layout
    .topSpaceToView(self.userPassword,kHeightScale(15))
    .leftEqualToView(self.userPassword)
    .widthIs(kWidthScale(55))
    .heightIs(kHeightScale(12));
    
    _registerNow.sd_layout
    .topEqualToView(self.forgetPassword)
    .leftSpaceToView(self.forgetPassword,kWidthScale(139))
    .rightEqualToView(self.userPassword)
    .heightIs(kHeightScale(12));
    
    _login.sd_layout
    .topSpaceToView(self.forgetPassword,kHeightScale(17))
    .leftSpaceToView(self.backgroundImage,kWidthScale(85))
    .rightSpaceToView(self.backgroundImage,kWidthScale(85))
    .heightIs(kHeightScale(36));
    
    _dividingImage.sd_layout
    .topSpaceToView(self.login,kHeightScale(15))
    .leftSpaceToView(self.backgroundImage,kWidthScale(64))
    .rightSpaceToView(self.backgroundImage,kWidthScale(64))
    .heightIs(kHeightScale(12));
    
    _QQLogin.sd_layout
    .topSpaceToView(self.dividingImage,kHeightScale(15))
    .leftSpaceToView(self.backgroundImage,kWidthScale(85))
    .widthIs(kWidthScale(44))
    .heightIs(kHeightScale(44));
    
    _WeChatLogin.sd_layout
    .topEqualToView(self.QQLogin)
    .leftSpaceToView(self.QQLogin,kWidthScale(34))
    .widthIs(kWidthScale(44))
    .heightIs(kHeightScale(44));
    
    _SinaLogin.sd_layout
    .topEqualToView(self.QQLogin)
    .leftSpaceToView(self.WeChatLogin,kWidthScale(34))
    .widthIs(kWidthScale(44))
    .heightIs(kHeightScale(44));
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (KQTextField *)userNum
{
    if (!_userNum)
    {
        _userNum = [[KQTextField alloc] init];
        _userNum.layer.borderWidth = 1;
        _userNum.layer.borderColor = [UIColor colorWithRed:66.0/255.0 green:167.0/255.0 blue:235.0/255.0 alpha:1].CGColor;
        _userNum.layer.cornerRadius = kWidthScale(6);
        _userNum.layer.masksToBounds = YES;
        _userNum.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shoujihao"]];
        _userNum.clearButtonMode = UITextFieldViewModeWhileEditing;
        _userNum.leftView.contentMode = UIViewContentModeScaleAspectFit; // 左视图图片自适应
        _userNum.leftViewMode = UITextFieldViewModeAlways; // 左视图图片一直显示
        _userNum.placeholder = @"手机号";
        _userNum.keyboardType = UIKeyboardTypeNumberPad;
        _userNum.tag = 400000;
    }
    return _userNum;
}

- (KQTextField *)userPassword
{
    if (!_userPassword)
    {
        _userPassword = [[KQTextField alloc] init];
        _userPassword.layer.borderWidth = 1;
        _userPassword.layer.borderColor = [UIColor colorWithRed:66.0/255.0 green:167.0/255.0 blue:235.0/255.0 alpha:1].CGColor;
        _userPassword.layer.cornerRadius = kWidthScale(6);
        _userPassword.layer.masksToBounds = YES;
        _userPassword.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mima"]];
        _userPassword.clearButtonMode = UITextFieldViewModeWhileEditing;
        _userPassword.leftView.contentMode = UIViewContentModeScaleAspectFit; // 左视图图片自适应
        _userPassword.leftViewMode = UITextFieldViewModeAlways; // 左视图图片一直显示
        _userPassword.placeholder = @"密码";
        _userPassword.secureTextEntry = YES;
        _userPassword.tag = 400001;
    }
    return _userPassword;
}

- (UIButton *)forgetPassword
{
    if (!_forgetPassword)
    {
        _forgetPassword = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetPassword setTitle:@"忘记密码" forState:0];
        [_forgetPassword setTitleColor:[UIColor colorWithRed:66.0/255.0 green:167.0/255.0 blue:235.0/255.0 alpha:1] forState:0];
        _forgetPassword.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _forgetPassword;
}

- (UIButton *)registerNow
{
    if (!_registerNow)
    {
        _registerNow = [UIButton buttonWithType:UIButtonTypeCustom];
        [_registerNow setTitle:@"立即注册" forState:0];
        [_registerNow setTitleColor:[UIColor colorWithRed:66.0/255.0 green:167.0/255.0 blue:235.0/255.0 alpha:1] forState:0];
        _registerNow.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(12)];
    }
    return _registerNow;
}

- (UIButton *)login
{
    if (!_login)
    {
        _login = [UIButton buttonWithType:UIButtonTypeCustom];
        _login.layer.borderWidth = 1;
        _login.layer.borderColor = [UIColor colorWithRed:66.0/255.0 green:167.0/255.0 blue:235.0/255.0 alpha:1].CGColor;
        _login.layer.cornerRadius = kWidthScale(18);
        _login.layer.masksToBounds = YES;
        [_login setTitle:@"登陆" forState:0];
        [_login setTitleColor:[UIColor colorWithRed:66.0/255.0 green:167.0/255.0 blue:235.0/255.0 alpha:1] forState:0];
        _login.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(14)];
    }
    return _login;
}

- (UIImageView *)dividingImage
{
    if (!_dividingImage)
    {
        _dividingImage = [[UIImageView alloc] init];
        _dividingImage.image = [UIImage imageNamed:@"disanfang"];
    }
    return _dividingImage;
}

- (UIButton *)QQLogin
{
    if (!_QQLogin)
    {
        _QQLogin = [UIButton buttonWithType:UIButtonTypeCustom];
        [_QQLogin setBackgroundImage:[UIImage imageNamed:@"qq"] forState:0];
    }
    return _QQLogin;
}

- (UIButton *)WeChatLogin
{
    if (!_WeChatLogin)
    {
        _WeChatLogin = [UIButton buttonWithType:UIButtonTypeCustom];
        [_WeChatLogin setBackgroundImage:[UIImage imageNamed:@"weixin"] forState:0];
    }
    return _WeChatLogin;
}

- (UIButton *)SinaLogin
{
    if (!_SinaLogin)
    {
        _SinaLogin = [UIButton buttonWithType:UIButtonTypeCustom];
        [_SinaLogin setBackgroundImage:[UIImage imageNamed:@"weibo"] forState:0];
    }
    return _SinaLogin;
}

- (UIImageView *)backgroundImage
{
    if (!_backgroundImage)
    {
        _backgroundImage = [[UIImageView alloc] init];
        _backgroundImage.image = [UIImage imageNamed:@"denglubg"];
        _backgroundImage.contentMode = UIViewContentModeScaleAspectFit;
        _backgroundImage.userInteractionEnabled = YES;
    }
    return _backgroundImage;
}

@end
